package com.study.studyroom.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.study.studyroom.constant.ApiConstant;
import com.study.studyroom.entity.bo.OptionBo;
import com.study.studyroom.entity.bo.RequestResult;
import com.study.studyroom.entity.bo.RoomBo;
import com.study.studyroom.entity.vo.Condition;
import com.study.studyroom.entity.vo.room.RoomVo;
import com.study.studyroom.service.RoomService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping(ApiConstant.API_V1+"room")
public class RoomController {

    private final RoomService roomService;

    @ApiOperation("分页获取自习室")
    @PostMapping("/getRoom")
    public RequestResult<IPage<RoomBo>> getRoom(@RequestBody Condition<RoomVo> condition){
        return RequestResult.success(roomService.getRoom(condition));
    }

    @ApiOperation("新增自习室")
    @PostMapping("/addRoom")
    public RequestResult<Integer> addRoom(@RequestBody RoomVo roomVo){
        return RequestResult.success(roomService.addRoom(roomVo));
    }
    //修改
    @ApiOperation("更新自习室")
    @PutMapping("/updateRoom")
    public RequestResult<RoomBo> updateRoom(@RequestBody RoomVo roomVo){
        return RequestResult.success(roomService.updateRoom(roomVo));
    }
    //停用
    @ApiOperation("起停用自习室")
    @GetMapping("/updateRoomStatus")
    public RequestResult<RoomBo> updateRoomStatus(Integer id){
        return RequestResult.success(roomService.updateRoomStatus(id));
    }
    //删除
    @ApiOperation("删除自习室")
    @GetMapping ("/deleteRoom")
    public RequestResult<Integer> deleteRoom(Integer id){
        return RequestResult.success(roomService.deleteRoom(id));
    }

    @ApiOperation("获取自习室信息")
    @GetMapping("/getRoomByName")
    public RequestResult<List<OptionBo>> getRoomByName(String name){
        return RequestResult.success(roomService.getRoomByName(name));
    }
}
